
import { reqMyBanner } from "../../request/api";

//初始值
const initState = {
    //定义轮播图的数组
    banner: []
};

//types
const types = {
    CHANGE_BANNER: "MINE_CHANGE_BANNER"
};

//修改数据
const reducer = (state = initState, action) => {
    switch (action.type) {
        case types.CHANGE_BANNER:
            return {
                ...state,
                banner: action.arr
            }
        default:
            return state;
    }
};

//组件派发的任务
export const actions = {
    //修改轮播图
    changeBanner: (arr) => ({ type: types.CHANGE_BANNER, arr }),
    //请求
    reqBanner: () => (dispatch, getState) => {
        reqMyBanner().then(res => {
            console.log("ok");
            if (res.data.code === 200) {
                dispatch(actions.changeBanner(res.data.list))
            }
        })
    }
};

//导出数据!
export const getBanner = (state) => state.mine.banner;

//整体导出
export default reducer;